package mshop.com.schild_kotlin.network

import android.content.Context
import android.widget.Toast
import com.orhanobut.logger.Logger
import io.reactivex.Observer
import io.reactivex.disposables.Disposable
import mshop.com.schild_kotlin.events.EventConstant
import mshop.com.schild_kotlin.events.MessageEvent
import org.greenrobot.eventbus.EventBus

/**
 * Created by mayi on 2018/5/28.
 * @Autor CaiWF
 * @Email 401885064@qq.com
 * @TODO
 */
abstract class MyObserver<T>(val mContext: Context) : Observer<T> {
    override fun onComplete() {

    }

    override fun onSubscribe(d: Disposable?) {

    }

    override fun onError(e: Throwable?) {
        Logger.d("onError  ---> " + e?.message)
        mContext.let {
            val event = MessageEvent(EventConstant.CancelHttpLoading, null)
            EventBus.getDefault().post(event)
            Toast.makeText(it, "请求服务器出错啦啦啦", Toast.LENGTH_LONG).show()
        }
    }

}